﻿using Microsoft.AspNetCore.Mvc;
using RobosimAPI.Class;

namespace RobosimAPI.Controllers
{
	[Route("back/Api2/Client/themeRuleDetails")]
	public class ThemeRuleDetailsController : ControllerBase
	{
		[HttpPost]
		public IActionResult GetThemeRuleDetails(ThemeRuleDetailsModel model)
		{
			string sign = HttpContext.Request.Headers["Sign"].ToString();
			string date = HttpContext.Request.Headers["Request-Date"].ToString();
			if (string.IsNullOrEmpty(sign) || string.IsNullOrEmpty(date))
			{
				//return Ok(new ErrorResponse() { status = -1, errmsg = "_ERROR_SIGN_" });
			}
			Account account = new Account(model.user_id);
			if (!account.SingnCheck(sign, date))
			{
				//return Ok(new ErrorResponse() { status = -1, errmsg = "_ERROR_SIGN_" });
			}
			Map[] map = Map.GetMapsWhereRuleId(model.rule_id);
			ThemeRule themeRule =new  ThemeRule(model.rule_id);
			var response = new RuleMapResponse();
			response.status = 1;
			response.ruleMap = new List<object>();
			response.ruleFile = themeRule.rule_file;
			response.introduction = themeRule.introduction;
			response.cover = themeRule.cover;
			response.map_cover = themeRule.map_cover;
			foreach (Map m in map)
			{
				if (m.limit== "专业训练" && !account.IsVip())
				{
					RuleMapItemNoVip item = new RuleMapItemNoVip();
					item.id = m.id;
					item.title = m.title;
					item.difficulty = m.difficulty;
					item.routine = m.routine;
					item.robot = m.robot;
					item.program = m.program;
					item.sort = m.sort;
					item.limit = m.limit;
					response.ruleMap.Add(item);
				}
				else
				{
					RuleMapItem item = new RuleMapItem();
					item.id = m.id;
					item.title = m.title;
					item.difficulty = m.difficulty;
					item.routine = m.routine;
					item.robot = m.robot;
					item.program = m.program;
					item.sort = m.sort;
					item.limit = m.limit;
					item.md5 = m.md5;
					item.map_pwd = m.map_pwd;
					item.map_url = m.map_url;
					response.ruleMap.Add(item);
				}
				
			}
			return Ok(response);
		}
		public class ThemeRuleDetailsModel
		{
			public int user_id { get; set; }
			public int rule_id { get; set; }
		}
		public class RuleMapItem
		{
			public int id { get; set; }
			public string title { get; set; }
			public int difficulty { get; set; }
			public int routine { get; set; }
			public string robot { get; set; }
			public string program { get; set; }
			public int sort { get; set; }
			public string limit { get; set; }
			public string md5 { get; set; }
			public string map_pwd { get; set; }
			public string map_url { get; set; }
		}
		public class RuleMapItemNoVip
		{
			public int id { get; set; }
			public string title { get; set; }
			public int difficulty { get; set; }
			public int routine { get; set; }
			public string robot { get; set; }
			public string program { get; set; }
			public int sort { get; set; }
			public string limit { get; set; }
		}
		public class RuleMapResponse
		{
			public int status { get; set; }
			public string cover { get; set; }
			public string map_cover { get; set; }
			public string introduction { get; set; }
			public string ruleFile { get; set; }
			public List<object> ruleMap { get; set; }
		}
	}
}
